package jp.seraph.jsade.model.nao;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import jp.seraph.jsade.message.MessageUtil;
import jp.seraph.jsade.model.Align;
import jp.seraph.jsade.model.JointIdentifier;

/**
 * Nao用のJointIdentifier<br>
 *
 */
public class NaoJointIdentifier implements JointIdentifier {
    public NaoJointIdentifier(String aName, Align aAlign, boolean aShouldMinus){
        mName = aName;
        mAlign = aAlign;
        mShouldMinus = aShouldMinus;
        if(mName.startsWith("l"))
            mMirrorIdentifier = "r" + mName.substring(1);
        else if(mName.startsWith("r"))
            mMirrorIdentifier = "l" + mName.substring(1);
        else
            mMirrorIdentifier = mName;

        IDENTIFIER_MAP.put(mName, this);
    }

    private String mName;
    private Align mAlign;
    private boolean mShouldMinus;
    private String mMirrorIdentifier;
    private static Map<String, NaoJointIdentifier> IDENTIFIER_MAP = new HashMap<String, NaoJointIdentifier>();

    public static NaoJointIdentifier getJointIdentifier(String aName){
        NaoJointIdentifier tResult = IDENTIFIER_MAP.get(aName);
        if(tResult == null)
            throw new IllegalArgumentException(MessageUtil.noJointFound(aName));

        return tResult;
    }

    public static Iterable<NaoJointIdentifier> getIdentifiers(){
        return IDENTIFIER_MAP.values();
    }

    public static Iterator<NaoJointIdentifier> getIterator(){
        return IDENTIFIER_MAP.values().iterator();
    }

    public static NaoJointIdentifier HJ1 = new NaoJointIdentifier("hj1", Align.CENTER, false);
    public static NaoJointIdentifier HJ2 = new NaoJointIdentifier("hj2", Align.CENTER, false);

    public static NaoJointIdentifier RAJ1 = new NaoJointIdentifier("raj1", Align.RIGHT, false);
    public static NaoJointIdentifier RAJ2 = new NaoJointIdentifier("raj2", Align.RIGHT, true);
    public static NaoJointIdentifier RAJ3 = new NaoJointIdentifier("raj3", Align.RIGHT, true);
    public static NaoJointIdentifier RAJ4 = new NaoJointIdentifier("raj4", Align.RIGHT, true);
    public static NaoJointIdentifier LAJ1 = new NaoJointIdentifier("laj1", Align.LEFT, false);
    public static NaoJointIdentifier LAJ2 = new NaoJointIdentifier("laj2", Align.LEFT, true);
    public static NaoJointIdentifier LAJ3 = new NaoJointIdentifier("laj3", Align.LEFT, true);
    public static NaoJointIdentifier LAJ4 = new NaoJointIdentifier("laj4", Align.LEFT, true);

    public static NaoJointIdentifier RLJ1 = new NaoJointIdentifier("rlj1", Align.RIGHT, false);
    public static NaoJointIdentifier RLJ2 = new NaoJointIdentifier("rlj2", Align.RIGHT, true);
    public static NaoJointIdentifier RLJ3 = new NaoJointIdentifier("rlj3", Align.RIGHT, false);
    public static NaoJointIdentifier RLJ4 = new NaoJointIdentifier("rlj4", Align.RIGHT, false);
    public static NaoJointIdentifier RLJ5 = new NaoJointIdentifier("rlj5", Align.RIGHT, false);
    public static NaoJointIdentifier RLJ6 = new NaoJointIdentifier("rlj6", Align.RIGHT, true);
    public static NaoJointIdentifier LLJ1 = new NaoJointIdentifier("llj1", Align.LEFT, false);
    public static NaoJointIdentifier LLJ2 = new NaoJointIdentifier("llj2", Align.LEFT, true);
    public static NaoJointIdentifier LLJ3 = new NaoJointIdentifier("llj3", Align.LEFT, false);
    public static NaoJointIdentifier LLJ4 = new NaoJointIdentifier("llj4", Align.LEFT, false);
    public static NaoJointIdentifier LLJ5 = new NaoJointIdentifier("llj5", Align.LEFT, false);
    public static NaoJointIdentifier LLJ6 = new NaoJointIdentifier("llj6", Align.LEFT, true);

    /**
     *
     * @see jp.seraph.jsade.model.JointIdentifier#toString()
     */

    public String toString() {
        return mName;
    }

    /**
     *
     * @see jp.seraph.jsade.model.JointIdentifier#toJointName()
     */

    public String toJointName() {
        return mName;
    }

    public Align getAlign(){
        return mAlign;
    }

    public NaoJointIdentifier getMirrorIdentifier(){
        return IDENTIFIER_MAP.get(mMirrorIdentifier);
    }

    public boolean shouldMinusAsMirror(){
        return mShouldMinus;
    }
}
